﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using NHibernate.Linq;

namespace JCSoft.Collect.Data
{
    public interface IUserRepository : INHibernateRepository<IUserRepository>
    {
        List<User> GetUsers(Expression<Func<User, bool>> predicate);

        User GetUser(Expression<Func<User, bool>> predicate);
    }

    public class UserRepository : NHibernateRepository<IUserRepository>, IUserRepository
    {
        #region IUserRepostory 成员

        public List<User> GetUsers(Expression<Func<User, bool>> predicate)
        {
            return this.Session.Linq<User>().Where(predicate).ToList();
        }

        public User GetUser(Expression<Func<User, bool>> predicate)
        {
            return this.Session.Linq<User>().FirstOrDefault(predicate);
        }

        #endregion
    }
}
